package Tydzien5;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.logging.*;

public class Tydzien5 {
	
	public static void writeToFile(String textToWrite, File file)
	{	
		try { 
			file.createNewFile(); // Utworzenie pliku pod sciezka zapisana w plik 
			Files.write(file.toPath(), textToWrite.getBytes(), StandardOpenOption.WRITE );
		}
		catch (IOException io) {
			Logger.getLogger("ExceptionLog").log(Level.SEVERE,io.getMessage());
		} 
		catch (Exception se) {
			Logger.getLogger("ExceptionLog").log(Level.SEVERE,"blad sec");
		}
	}
	
	public static String readFromFile(File file) throws IOException
	{
		try {  
			return new String(Files.readAllBytes(file.toPath()));
		} 
		catch (FileNotFoundException io) {
			Logger.getLogger("ExceptionLog").log(Level.SEVERE,io.getMessage());
			throw io;
		} 
		catch (IOException io) {
			Logger.getLogger("ExceptionLog").log(Level.SEVERE,io.getMessage());
			throw io;
		}
	}
	
	public static void writeArrayToFile(byte[] arrayToWrite, File file)
	{
		try { 
			file.createNewFile(); // Utworzenie pliku pod sciezka zapisana w plik 
			Files.write(file.toPath(), arrayToWrite, StandardOpenOption.WRITE);
		} 
		catch (IOException io) {
			Logger.getLogger("ExceptionLog").log(Level.SEVERE,io.getMessage());
		} 
		catch (Exception se) {
			Logger.getLogger("ExceptionLog").log(Level.SEVERE,"blad sec");
		}
	}
	
	public static byte[] readArrayFromFile(File file) throws IOException
	{
		try { 
			return Files.readAllBytes(file.toPath());
		} 
		catch (FileNotFoundException io) {
			Logger.getLogger("ExceptionLog").log(Level.SEVERE,io.getMessage());
			throw io;
		} 
		catch (IOException io) {
			Logger.getLogger("ExceptionLog").log(Level.SEVERE,io.getMessage());
			throw io;
		}
	}
	
}
